package com.dc.business.datacollectbusiness.service.impl;

import com.dc.business.datacollectbusiness.entity.Equipment;
import com.dc.business.datacollectbusiness.entity.Line;
import com.dc.business.datacollectbusiness.mapper.EquipmentMapper;
import com.dc.business.datacollectbusiness.mapper.LineMapper;
import com.dc.business.datacollectbusiness.service.EquipmentService;
import com.dc.business.datacollectbusiness.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentMapper equipmentmapper;

    @Autowired
    private LineMapper lineMapper;

    @Override
    public List<Equipment> getAllEquipmentByLineId(Integer lineId) {
        return equipmentmapper.selectAllEquipmentByLineId(lineId);
    }

    @Override
    public void addEquipment(Equipment equipment) {
        Map<String,Object> map = new HashMap<>();
        map= ThreadLocalUtil.get();
        equipment.setCreateBy(map.get("username").toString());
        equipment.setUpdateBy(map.get("username").toString());
        equipmentmapper.insertEquipment(equipment);
    }

    @Override
    public void updateEquipment(Equipment equipment) {
        Map<String,Object> map = new HashMap<>();
        map= ThreadLocalUtil.get();
        equipment.setUpdateBy(map.get("username").toString());

        Line line=new Line();
        line.setLineId(equipment.getLineId());
        lineMapper.updateLine2(line);
        equipmentmapper.updateEquipment(equipment);
    }

    @Override
    public void deleteEquipmentByEquipmentId(Integer equipmentId) {

    }
}
